package com.gitee.cirnochat.user.model.vo.req.user;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.Null;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDate;

/**
 * 用户信息更新DTO
 */
@Schema(description = "用户信息更新DTO")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserInfoUpdateRequest implements Serializable {
    @Null(message = "非法字段注入")
    @Schema(hidden = true)
    private Long userId;

    /**
     * 用户唯一凭证
     */
    @Schema(description = "用户唯一凭证")
    private String uuid;

    @AssertTrue(message = "用户唯一凭证不能为空且必须符合校验规则")
    private boolean isUuidValid() {
        return uuid == null || (!uuid.isBlank() && uuid.length() >= 10 && uuid.length() <= 20 && uuid.matches("^[a-zA-Z0-9]+$"));
    }

        /**
         * 昵称
         */
    @Schema(description = "昵称")
    private String nickname;

    @AssertTrue(message = "昵称长度不能超过20个字符")
    private boolean isNicknameValid() {
        return nickname == null || nickname.length() <= 20;
    }


    /**
     * 性别：0保密 1男 2女
     */
    @Schema(description = "性别：0保密 1男 2女")
    private Integer gender;

    @AssertTrue(message = "性别编号必须在0到2之间")
    private boolean isGenderValid() {
        return gender == null || (gender >= 0 && gender <= 2);
    }

    /**
     * 地区
     */
    @Schema(description = "地区")
    private String region;

    @AssertTrue(message = "地区不能为空")
    private boolean isRegionValid() {
        return region == null || !region.isBlank();
    }

    /**
     * 手机号码
     */
    @Schema(description = "手机号码")
    private String mobile;

    @AssertTrue(message = "手机号码格式不正确")
    private boolean isMobileValid() {
        return mobile == null || (!mobile.isBlank() && mobile.matches("^\\+?[0-9]{10,15}$"));
    }

    /**
     * 出生日期
     */
    @Schema(description = "出生日期")
    private LocalDate birthday;

    @AssertTrue(message = "出生日期不能是未来的日期")
    private boolean isBirthdayValid() {
        return birthday == null || !birthday.isAfter(LocalDate.now());
    }
    /**
     * 个性签名
     */
    @Schema(description = "个性签名")
    private String signature;

    @AssertTrue(message = "个性签名不能为空")
    private boolean isSignatureValid() {
        return signature == null || !signature.isBlank();
    }

}